package StringC;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-03-01
 * Time:17:57
 * Text：14. 最长公共前缀
 */
public class Text1 {
    public String longestCommonPrefix(String[] strs) {
        if(strs.length==0){
            return new String();
        }
        int i=0;
        StringBuffer str=new StringBuffer();
        while(i<strs[0].length()){
            int j=1;
            char by=strs[0].charAt(i);
            while(j<strs.length){
                if(i>=strs[j].length() || by!=strs[j].charAt(i)){
                    return str.toString();
                }
                j++;
            }
            str.append(by);
            i++;
        }
        return str.toString();
    }
}
